home *** CD-ROM | disk | FTP | other *** search
-
- #include <math.h>
- #include <DeskBus.h>
-
- #include "PrefResource.h"
-
- #include "ADBServiceProc.h"
-
- #define kMouseADBAddress 3
- #define TwosComplement(n) ((~(n)) + 1)
-
- #define kButtonStateMask 0x80
- #define kValueMask 0x7F
-
-
- // global data polity
- //
- // The install routines create a ptr in the sys heap, and install a Gestalt value with
- // its address. They also set up a global for the service routines.
- //
-
- TPrefsDataPtr gADBGlobals; // ptr in sys heap
-
- void main(void);
-
-
- #define ROTATE_AXES
-
- #if TARGET_CPU_68K
-
- asm void MyCallADBServiceProc(Ptr buffer, TempADBServiceRoutineUPP completionProc, Ptr refCon, long command, ADBServiceRoutineUPP foo)
- {
- _Debugger
- link a6,#0
- move.l a4, -(a7)
- move.l 0x18(a6), a4
- move.l 0x14(a6),d0
- movea.l 0x10(a6),a2
- movea.l 0x0C(a6),a1
- movea.l 0x8(a6),a0
- jsr 0(a4)
- move.l (a7)+,a4
- unlk a6
- rts
- }
-
- #endif
-
-
- /*----------------------------------------------------------------------------
- ADBMouseServiceRoutine
-
- Handler for Mouse service routine
- ----------------------------------------------------------------------------*/
- pascal void ADBMouseServiceRoutine(Ptr buffer, TempADBServiceRoutineUPP completionProc, long refCon, long command)
- {
- unsigned char num, buttonstate, count;
-
- for (count = 0; count < buffer[0]; count++)
- {
- // high most bit is the button state
- // get the x and y data and take the 2's complement to reverse direction
-
- buttonstate = buffer[count + 1] & kButtonStateMask;
- num = buffer[count + 1] & kValueMask;
-
- #if REVERSE_DIRECTION
- // swap left right and up down
- num = TwosComplement(num);
- #endif
- buffer[count + 1] = (num & kValueMask) | (buttonstate & kButtonStateMask);
- }
-
- #if CHANGE_BUTTON_STATE
- // swap button up and button down
- buffer[1] = (buffer[1] & kValueMask) | (~(buffer[1]) & kButtonStateMask);
- #endif
-
- #ifdef ROTATE_AXES
-
- for (count = 1; count < buffer[0]; count++)
- {
- UInt8 button1State = buffer[count] & kButtonStateMask;
- UInt8 button2State = buffer[count + 1] & kButtonStateMask;
-
- SInt8 xAfter, xMoved = (buffer[count] & kValueMask);
- SInt8 yAfter, yMoved = (buffer[count + 1] & kValueMask);
-
- double xDiff, yDiff;
- double xNew, yNew;
- double xSign, ySign;
- double hypot, theta;
-
- // promote the sign bit if -ve
- xMoved |= (xMoved & 0x40) << 1;
- yMoved |= (yMoved & 0x40) << 1;
-
- // my brain is too tired to figure out better logic here.
- if (xMoved < 0 == yMoved < 0)
- {
- // NE or SW quadrant (assuming +ve is up)
- xSign = (xMoved < 0) ? -1.0 : 1.0;
- ySign = (yMoved < 0) ? -1.0 : 1.0;
- }
- else if (xMoved < 0)
- {
- // NW quadrant
- xSign = -1.0;
- ySign = -1.0;
- }
- else
- {
- // SE quadrant
- xSign = 1.0;
- ySign = 1.0;
- }
-
- xDiff = (double)xMoved;
- yDiff = (double)yMoved;
-
- hypot = sqrt(xDiff * xDiff + yDiff * yDiff);
- theta = atan(yDiff / xDiff);
-
- theta += gADBGlobals->thetaDelta;
-
- xNew = hypot * cos(theta) * xSign;
- yNew = hypot * sin(theta) * ySign;
-
- xAfter = (SInt8)xNew;
- yAfter = (SInt8)yNew;
-
- buffer[count] = (button1State | (xAfter & kValueMask));
- buffer[count + 1] = (button2State | (yAfter & kValueMask));
- }
-
- #endif
-
- #if TARGET_CPU_68K
- MyCallADBServiceProc(buffer, completionProc, (Ptr)gMouseADBinfo.dbDataAreaAddr, command, gOldMouseServiceRoutine);
- #else
- CallADBServiceRoutineProc(gADBGlobals->oldMouseServiceRoutine, buffer, completionProc, (long)gADBGlobals->mouseADBinfo.dbDataAreaAddr, command);
- #endif
- }
-
- /*----------------------------------------------------------------------------
- MyInstallServiceRoutines
-
- Setup our service routines
- ----------------------------------------------------------------------------*/
- Boolean MyInstallServiceRoutines(void)
- {
- short adbcount, adbindex;
- OSErr err = paramErr;
-
- adbcount = CountADBs();
-
- for (adbindex = 1; adbindex <= adbcount; adbindex++)
- {
- ADBDataBlock adb_data;
- long adbaddr = GetIndADB(&adb_data, adbindex);
-
- if ((adb_data.origADBAddr == kMouseADBAddress))
- {
- ADBSetInfoBlock setADBInfo;
-
- BlockMoveData(&adb_data, &gADBGlobals->mouseADBinfo, sizeof(ADBDataBlock));
- // Remember we will be called once to install and twice during each ADBReInit
- if (!gADBGlobals->myMouseServiceRoutine)
- {
- THz curZone = GetZone();
- SetZone(SystemZone());
- gADBGlobals->myMouseServiceRoutine = NewADBServiceRoutineProc(ADBMouseServiceRoutine);
- SetZone(curZone);
- }
- if (!gADBGlobals->myMouseServiceRoutine)
- return false;
-
- gADBGlobals->oldMouseServiceRoutine = adb_data.dbServiceRtPtr;
- setADBInfo.siService = gADBGlobals->myMouseServiceRoutine;
- setADBInfo.siDataAreaAddr = adb_data.dbDataAreaAddr;
-
- err = SetADBInfo(&setADBInfo, adbaddr);
- return (err == noErr);
- }
- }
-
- return false;
- }
-
-
- /*----------------------------------------------------------------------------
- MyADBInitProc
-
- needed to re-install our service routine
- ----------------------------------------------------------------------------*/
- void MyADBInitProc(SInt8 callOrder)
- {
- Boolean InstallOK;
-
- CallADBInitProc(gADBGlobals->oldADBInitProc, callOrder);
- if (callOrder)
- InstallOK = MyInstallServiceRoutines();
- }
-
-
- /*----------------------------------------------------------------------------
- SetupData
-
- needed to re-install our service routine
- ----------------------------------------------------------------------------*/
- OSErr SetupData(void)
- {
- // Set up our global data
- return Gestalt(kDataGestaltSelector, (long *)&gADBGlobals);
- }
-
-
- ProcInfoType __procinfo = kThinkCStackBased;
-
- void main(void)
- {
- //nothing to do
- }
-
-